package com.violet.repository.module;


import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;

import com.violet.repository.network.ApiServices;
import com.violet.repository.network.okhttp.OkHttpEngine;
import com.violet.repository.repository.IRepositoryManager;
import com.violet.repository.repository.RepositoryManager;
import com.violet.repository.repository.kotlin.data.CommDataSource;
import com.violet.repository.repository.kotlin.data.OrderDataSource;
import com.violet.repository.repository.kotlin.data.source.CommRepository;
import com.violet.repository.repository.kotlin.data.source.OrderRepository;

import javax.inject.Singleton;

import dagger.Binds;
import dagger.Module;
import dagger.Provides;
import dagger.hilt.InstallIn;
import dagger.hilt.components.SingletonComponent;

/**
 * 数据仓库相关
 */
@InstallIn(SingletonComponent.class)
@Module
public abstract class RepositoryModule {

    @Provides
    static Context provideContext(Application application) {
        return application.getApplicationContext();
    }

    @Provides
    static SharedPreferences provideSharePreferences(Application context) {
        return context.getSharedPreferences("johomesdk", Context.MODE_PRIVATE);
    }

    @Singleton
    @Binds
    abstract IRepositoryManager bindRepositoryManager(RepositoryManager manager);

    @Binds
    abstract CommDataSource bindCommDataSource(CommRepository repository);

    @Binds
    abstract OrderDataSource bindOrderDataSource(OrderRepository repository);

    @Singleton
    @Provides
    static ApiServices provideApiServices(Application context, SharedPreferences sp) {
        return OkHttpEngine.get(sp).create(ApiServices.class, context, "https://www.baidu.com/");
    }
}
